<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ include file="inc/taglibs.jsp" %>
<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <%@ include file="inc/meta.jsp" %>
    <meta name="description" content="">
    <meta name="author" content="">
    <title>编辑营业网点</title>
    <%@ include file="inc/css.jsp" %>
</head>
<body>

<div class="wrapper">
    <%@ include file="inc/nav.jsp" %>
    <div id="page-wrapper">
        <div class="row">
            <div class="col-lg-12">
                <h1 class="page-header">营业网点</h1>
                <h4 style="margin-left: 10px;">——编辑营业网点</h4>
            </div>
        </div>
        <div class="row">
            <div class="col-lg-12">
                <div class="panel panel-default">
                    <!-- /.panel-heading -->
                    <div class="panel-body">
                        <form class="form-horizontal nice-validator n-default" novalidate="novalidate">
                            <input type="hidden" id="outletId" value="${outlet.id}"/>
                            <input type="hidden" id="areaId" value="${areaId}"/>

                            <div class="form-group">
                                <label class="col-sm-2 control-label">名称:</label>
                                <div class="col-sm-8">
                                    <input type="text" class="form-control" id="name" name="name" maxlength="20" data-rule="required" value="${outlet.name}" placeholder="请输入名称"/>
                                </div>
                            </div>

                            <div class="form-group">
                                <label class="col-sm-2 control-label">地址:</label>
                                <div class="col-sm-8">
                                    <select class="form-control" id="areaList" style="width: 10%"></select>
                                    <input type="text" style="width: 80%" class="form-control" id="address" name="address" maxlength="50" data-rule="required" value="${outlet.address}" placeholder="请输入详细地址"/>
                                </div>
                            </div>

                            <div class="form-group">
                                <label class="col-sm-2 control-label">电话:</label>
                                <div class="col-sm-8">
                                    <input type="text" class="form-control" id="phone" name="phone" maxlength="20" data-rule="required" value="${outlet.phone}" placeholder="请输入电话"/>
                                </div>
                            </div>

                            <div class="form-group">
                                <label class="col-sm-2 control-label">公司简介:</label>
                                <div class="col-sm-8">
                                    <textarea cols="40" rows="8" class="form-control" style="resize: none" id="description">${outlet.description}</textarea>
                                </div>
                            </div>

                            <div class="form-group">
                                <div class="col-sm-10" style="text-align: center">
                                    <a href="javascript:void(0)" class="btn btn-success" role="button" onclick="_infoDetail.fn.subInfo()">保存</a>
                                    <a href="backend/outlet/index" class="btn btn-primary" role="button">返回</a>
                                </div>
                            </div>
                        </form>
                    </div>
                </div>
                <!-- /.panel -->
            </div>
        </div>
    </div>
    <!-- /#page-wrapper -->
</div>
<!-- /#wrapper -->
<%@ include file="inc/footer.jsp" %>
</body>
</html>
<script type="text/javascript">
    var _infoDetail = {
        v: {
            id: "_infoDetail",
            list: [],
            dTable: null
        },
        fn: {
            checkData: function () {
                var flag = true;
                var name = $('#name').val();
                var address = $('#address').val();
                var phone = $('#phone').val();
                var description = $('#description').val();

                if (null == name || name == '') {
                    $sixmac.notify("请输入名称", "error");
                    flag = false;
                    return;
                }

                if (null == address || address == '') {
                    $sixmac.notify("请输入详细地址", "error");
                    flag = false;
                    return;
                }

                if (null == phone || phone == '') {
                    $sixmac.notify("请输入电话", "error");
                    flag = false;
                    return;
                }

                if (null == description || description == '') {
                    $sixmac.notify("请输入公司简介", "error");
                    flag = false;
                    return;
                }

                return flag;
            },
            getSelectInfo: function () {
                var areaId = $('#areaId').val();

                $sixmac.ajax("common/areaList", null, function (result) {
                    if (null != result) {
                        // 获取返回的区域列表信息，并循环绑定到label中
                        var content = "";
                        jQuery.each(result, function (i, item) {
                            if (item.id == areaId) {
                                content += "<option value='" + item.id + "' selected>" + item.name + "</option>";
                            } else {
                                content += "<option value='" + item.id + "'>" + item.name + "</option>";
                            }
                        });
                        $('#areaList').append(content);
                    } else {
                        $sixmac.notify("获取区域信息失败", "error");
                    }
                });
            },
            subInfo: function () {
                // 所有的验证通过后，执行新增操作
                if (_infoDetail.fn.checkData()) {
                    $.post(_basePath + "backend/outlet/save",
                            {
                                "id": $('#outletId').val(),
                                "name": $('#name').val(),
                                "areaId": $('#areaList option:selected').val(),
                                "address": $('#address').val(),
                                "phone": $('#phone').val(),
                                "description": $('#description').val()
                            },
                            function (data) {
                                if (data > 0) {
                                    window.location.href = _basePath + "backend/outlet/index";
                                } else {
                                    $sixmac.notify("操作失败", "error");
                                }
                            });
                }
            }
        }
    }

    $(function () {
        _infoDetail.fn.getSelectInfo();
    });
</script>